// 2025/5/27
// kotori和素因子

#include <climits>
#include <iostream>
#include <vector>
using namespace std;

vector<int> GetFactories(int n)
{
    vector<int> ans;
    for (int i = 2; i <= n; i++)
    {
        if (n % i == 0)
        {
            ans.emplace_back(i);
            while (n % i == 0)
            {
                n /= i;
            }
        }
    }
    return ans;
}

int ans = -1;
vector<bool> isused(1001, false);
void dfs(vector<vector<int>>& factories, int pos, int cur)
{
    if (pos == factories.size())
    {
        if(ans == -1 || cur < ans) ans = cur;
        return;
    }

    int n = factories[pos].size();
    for (int i = 0; i < n; i++)
    {
        int factory = factories[pos][i];
        if (isused[factory]) continue;
        isused[factory] = true;
        dfs(factories, pos + 1, cur + factory);
        isused[factory] = false;
    }
}

int main() {
    int n, tmp; cin >> n;
    vector<vector<int>> factories(n);
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        factories[i] = GetFactories(tmp);
    }
    dfs(factories, 0, 0);
    cout << ans << endl;
}
// 64 位输出请用 printf("%lld")